package com.lsyw.intergrate.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lsyw.intergrate.entity.vo.MassifModelVo;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lsyw.intergrate.entity.common.PageInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lsyw.intergrate.common.Result;
import org.springframework.util.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import com.lsyw.intergrate.service.MassifModelService;
import com.lsyw.intergrate.entity.MassifModel;

import java.util.*;

import io.swagger.annotations.Api;
import lombok.Data;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 地块模型绑定信息 前端控制器
 * </p>
 *
 * @author 刘磊
 * @since 2023-12-06
 */
@Api(tags = "地块模型绑定信息")
@RestController
@RequestMapping("/massif-model")
public class MassifModelController {


    @Autowired
    private MassifModelService massifModelService;


    /**
     * 新增
     */
    @PostMapping("/saveOrUpdateBatch")
    public Result saveOrUpdateBatch(@RequestBody MassifModelVo massifModelVo) {
        LambdaQueryWrapper<MassifModel> lambda = new QueryWrapper<MassifModel>().lambda();
        lambda.eq(MassifModel::getMassifId, massifModelVo.getMassifId());
        lambda.eq(MassifModel::getDelFlag, 0);
        MassifModel massifModel = new MassifModel();
        massifModel.setDelFlag(1);
        massifModel.setGmtModified(new Date());
        massifModelService.update(massifModel, lambda);
        if (!CollectionUtils.isEmpty(massifModelVo.getMassifModelList())) {
            massifModelVo.getMassifModelList().forEach(e -> {
                e.setMassifId(massifModelVo.getMassifId());
                e.setId(null);
                e.setDelFlag(0);
                e.setGmtCreate(new Date());
            });
            massifModelService.saveOrUpdateBatch(massifModelVo.getMassifModelList());
        }
        return Result.successResult(null);
    }


    /**
     * 根据地块信息查询
     */
    @GetMapping("/getListByMassifId")
    public Result getListByMassifId(String massifId) {
        return Result.successResult(massifModelService.getListByMassifId(massifId));
    }


}
